package cn.train.service;


import java.util.List;

import org.apache.ibatis.session.SqlSession;


import cn.train.dao.IEditTrain;
import cn.train.model.Carpiao;
import cn.train.model.Cartable;
import cn.train.util.SqlSessionFactoryUtil;

public class EditTrainServices {
	SqlSession session=SqlSessionFactoryUtil.getSqlSession();
	IEditTrain iedt=session.getMapper(IEditTrain.class);
	//鑾峰彇鍒楄溅淇℃伅鎬绘暟
	public int getCount(){
		return iedt.getCount();
	}
	//鑾峰彇鎵�鏈夌殑鍒楄溅淇℃伅
	public List<Carpiao> getUserByPage(int pageIndex,int pageSize){
		pageIndex=(pageIndex-1)*pageSize;
		return iedt.findAll(pageIndex,pageSize);
	}
	//鍒犻櫎鎸囧畾鍒楄溅
	public int del(int id){
		int m=iedt.del(id);
		session.commit();
		return m;
	}
	public int update(Carpiao carpiao){
		Cartable ct=new Cartable();
		ct.setCarid(carpiao.getCartable().getCarid());
		ct.setCrname(carpiao.getCartable().getCrname());
		ct.setCtype(carpiao.getCartable().getCtype());
		ct.setNum(carpiao.getCartable().getNum());
		int m=iedt.update(carpiao);
		int n=iedt.updatect(ct);
		session.commit();
		return m+n; 
	}

}
